using System.Web.UI;
using Portal.Core;
using Portal.Data.Entity;


namespace Portal.Data.Webparts
{
    public class DragDropContainer : Control, IContainer
    {
        #region IContainer Members

        private string _uniqueId;
        private WebpartControl _part;
        private WebpartMenu _menu;
        private WebpartDefinition _definition;
        public string Title
        {
            set
            { }
        }

        public WebpartMenu Menu
        {
            set
            {
                _menu = value;
            }
        }

        public void Add(WebpartControl webPart)
        {
            _part = webPart;
            _uniqueId = "_wp" + webPart.Info.ID;
            _definition = _part.Info.Definition();
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("<div class='draggable'");
            writer.Write(" id=\"" + _uniqueId + "\">");

            writer.Write("<div>");
            if (!string.IsNullOrEmpty(_definition.Icon))
                writer.Write("<img style='float:left;' src='" + CoreContext.absStaticFile + _definition.Icon + "'/>");

            writer.Write("(" + _definition.Name + ")-" + _part.Config.Title);

            //writer.Write("<img src='Themes/Images/space.gif'/>");
            _menu.RenderControl(writer);
            writer.Write("<div></div>");
            writer.Write("</div>");
            try
            {
                _part.RenderControl(writer);
            }
            catch {
                writer.Write("<div style='color:red;font-style:italic'>Error build</div>");
            }
            writer.Write("</div>");
        }

        #endregion
    }
}
